package com.personal.kousuan.generator;

import java.util.Random;

import com.personal.kousuan.domain.Question;
import com.personal.kousuan.factory.RandomGeneratorFactory;
import com.personal.kousuan.random.RandomGenerator;

public abstract class PlusMinusKouSuanGenerator implements KouSuanGenerator {

	

	@Override
	public Question generateKouSuanTi() {
		
		//个位
		int i = new Random().nextInt(getGetWeiMax());
		
		RandomGenerator randomGenerator = null;
		if(isJinWei()){
			randomGenerator = RandomGeneratorFactory.getInstance().getRandomGenerator(RandomGeneratorFactory.JINWEI_RANDOM_GENERATOR);
		}else{
			randomGenerator = RandomGeneratorFactory.getInstance().getRandomGenerator(RandomGeneratorFactory.BUJINWEI_RANDOM_GENERATOR);
		}
		
		//另外一个数的个位
		int j = randomGenerator.generateRandom(i);
		
		
		//十位
		int k = new Random().nextInt(getShiWeiMax());
		
		randomGenerator = RandomGeneratorFactory.getInstance().getRandomGenerator(RandomGeneratorFactory.BUJINWEI_RANDOM_GENERATOR);
		
		int l = randomGenerator.generateRandom(k);
		
		int one = k * 10 + i;
		int two = l * 10 + j;
		Question question = new Question();
		question.setQuestion(one + "+" + two);
		question.setAnswer(String.valueOf(one  + two));
		return question;
		
	}
	public abstract int getMax();
	public abstract boolean isJinWei();
	public abstract boolean isContinuousCalculation();
	public abstract int getGetWeiMax();
	public abstract int getShiWeiMax();
	

}
